package com.gz.purchase.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.gz.purchase.R;
import com.gz.purchase.app.InStorageActivity;
import com.gz.purchase.app.InStorageHistoryActivity;
import com.gz.purchase.app.MoveInStorageConfirmActivity;
import com.gz.purchase.app.OutStorageCartActivity;
import com.gz.purchase.app.OutStorageHistoryActivity;
import com.gz.purchase.app.StorageCheckActivity;
import com.gz.purchase.library.IAuthor;
import com.gz.purchase.library.pojo.UserInfo;
import com.gz.purchase.library.util.Constants;
import com.gz.purchase.library.util.PreferenceModel;

public class StoreFragment extends Fragment implements View.OnClickListener {
    private View mConvertView;
    private TextView tv_actionbar_title;
    private TextView tv_actionbar_deliveryName;
    private Button bt_store_check;
    private Button bt_out_storage;
    private Button bt_in_storage;
    private Button bt_move_in_confirm;
    private Button bt_in_storage_history;
    private Button bt_out_storage_history;
    private UserInfo info ;
    private Context mContext;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (mConvertView == null){
            mConvertView = inflater.inflate(R.layout.fragment_store, container, false);
            initView();
        }
        initListener();
        initData();
        return mConvertView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ((ViewGroup)mConvertView.getParent()).removeView(mConvertView);
    }

    public void initView() {
        mContext = getActivity();
        info = IAuthor.getInstance().loadUserInfoSyn(PreferenceModel.getInt(Constants.PREFERENCE_USER_ID, -1));
        tv_actionbar_title = (TextView) mConvertView.findViewById(R.id.tv_actionbar_title);
        tv_actionbar_deliveryName = (TextView) mConvertView.findViewById(R.id.tv_actionbar_deliveryName);
        bt_store_check = (Button) mConvertView.findViewById(R.id.bt_store_check);
        bt_out_storage = (Button) mConvertView.findViewById(R.id.bt_out_storage);
        bt_in_storage = (Button) mConvertView.findViewById(R.id.bt_in_storage);
        bt_move_in_confirm = (Button) mConvertView.findViewById(R.id.bt_move_in_confirm);
        bt_in_storage_history = (Button) mConvertView.findViewById(R.id.bt_in_storage_history);
        bt_out_storage_history = (Button) mConvertView.findViewById(R.id.bt_out_storage_history);
    }
    public void initListener(){

        bt_store_check.setOnClickListener(this);
        bt_out_storage.setOnClickListener(this);
        bt_in_storage.setOnClickListener(this);
        bt_move_in_confirm.setOnClickListener(this);
        bt_in_storage_history.setOnClickListener(this);
        bt_out_storage_history.setOnClickListener(this);

    }

    public void initData(){
        tv_actionbar_title.setText("库存出入");
        if (info != null){
            tv_actionbar_deliveryName.setText(info.getName()+":"+info.getUser_name());
        }

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_store_check://库存查看
                Intent intent = new Intent();
                intent.setClass(mContext, StorageCheckActivity.class);
                startActivity(intent);
                break;
            case R.id.bt_out_storage:// 出库车出库
                Intent intent2 = new Intent();
                intent2.setClass(mContext, OutStorageCartActivity.class);
                startActivity(intent2);
                break;
            case R.id.bt_in_storage: // 入库
                Intent intent3 = new Intent();
                intent3.setClass(mContext, InStorageActivity.class);
                startActivity(intent3);
                break;
            case R.id.bt_move_in_confirm://移库入库确认
                Intent intent4 = new Intent();
                intent4.setClass(mContext, MoveInStorageConfirmActivity.class);
                startActivity(intent4);
                break;
            case R.id.bt_in_storage_history:// 入库历史查询
                Intent intent5 = new Intent();
                intent5.setClass(mContext, InStorageHistoryActivity.class);
                startActivity(intent5);
                break;
            case R.id.bt_out_storage_history:// 出库历史查询
                Intent intent6 = new Intent();
                intent6.setClass(mContext, OutStorageHistoryActivity.class);
                startActivity(intent6);
                break;

        }


    }
}
